package graphic;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.DisplayMode;
import java.awt.FlowLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.WindowConstants;
import javax.swing.border.EmptyBorder;
import java.awt.Color;

public class ErrorMessage extends JDialog {

	private final JPanel contentPanel = new JPanel();
	private String message;
	final Toolkit toolkit = Toolkit.getDefaultToolkit();
	final Dimension screenSize = toolkit.getScreenSize();

	/**
	 * Create the dialog.
	 */
	public ErrorMessage(String error) {
		setBackground(Color.GRAY);
		setAlwaysOnTop(true);
		setResizable(false);
		message = error;
		
		this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
		setSize(200, 100);
		setLocation((int) (screenSize.getWidth() - this.getWidth()) / 2,(int) (screenSize.getHeight() - this.getHeight()) / 2);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setLayout(new FlowLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		{
			JPanel buttonPane = new JPanel();
			JLabel mess = new JLabel(message);
			mess.setHorizontalAlignment(SwingConstants.CENTER);
			buttonPane.setLayout(new FlowLayout(FlowLayout.CENTER));
			getContentPane().add(mess, BorderLayout.CENTER);
			getContentPane().add(buttonPane, BorderLayout.SOUTH);
			{
				JButton okButton = new JButton("OK");
				okButton.addActionListener(new ActionListener() {					
					@Override
					public void actionPerformed(ActionEvent arg0) {
						dispose();
					}
				});
				buttonPane.add(okButton);
				getRootPane().setDefaultButton(okButton);
			}
		}
	}

}
